<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <!-- 工具 -->
    <script src="js/HttpUtil.js"></script>
    <title>添加商品种类</title>
    <script>

    </script>
</head>
<body>
<div style="width:98%;margin-left: 1%;">
    <div class="panel panel-default">
        <div class="panel-heading">
            添加商品种类
        </div>
        <div class="panel-body center-block">
            <form  method="post">
                <div class="row">
                    <span style="float:left;margin: 15px">商品分类：</span>
                        <ul class="list-group " id="ul_type" style="list-style: none">
                        </ul>
                </div>
                <div class="row">
                    <div class="form-group form-inline" style="margin-left: 15px;">
                        <span>种类名称</span>
                        <input type="text" name="typename" class="form-control" id="typename">
                    </div>
                </div>
                <div class="row">
                    <div class="btn-group" style="margin-left: 15px;">
                        <button type="reset" class="btn btn-default" >清空</button>
                        <button type="submit" class="btn btn-default" onclick="addType($('#typename'))">添加</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    $(document).ready(function(){
        loadType();
    });
    //请求信息
    function loadType(){
        //ajax 请求后台
        var url="adminType/select";
        url=appendHost(url);
        $.ajax({
            url:url,
            method:"post",
            success:function (resp) {
                handleResp(resp,function (res) {
                    console.log("showGoodsType")
                    console.log(res);
                    var html = res.map(function (s) {
                        var template =
                            `<li style="float: left;margin: 15px">${s.typeName}</li>`;
                        return template
                    }).join("");
                    $("#ul_type").html(html);
                });
            },
            error:function(XMLHttpRequest,textStatus,errorThrown){
                alert("失败"+XMLHttpRequest.status+":"+textStatus+":"+errorThrown);
            }
        });
    }
    //添加商品分类
    function addType() {
        if (confirm("确认要添加吗?")) {
            let url = "adminType/add";
            let params = {
                typeName:$("#typename").val()
            };
            console.log(params);
            httpPost(url, params, function () {
                loadType();
            });
        }
    }
</script>
</body>
</html>